<template>
    <div>
        <div class="activity-right coupon">
            <h3>编辑优惠券</h3>
            <div class="select_type">
                <el-form :label-position="labelPosition" ref="form" :rules="rules" v-if="form" :model="form" label-width="150px">
                    <el-form-item label="优惠券名称:" prop="name">
                        <el-input style="width:400px" prop="name" v-model="form.name" type="text" placeholder="请输入优惠券名称" clearable></el-input>
                    </el-form-item>
                    <el-form-item label="优惠券种类:" prop="type">
                        <el-select style="width:400px" v-model="form.type" placeholder="选择优惠券种类">
                            <el-option v-for="item in option" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="抵扣金额:" prop="couponAmount">
                        <el-input style="width:400px" v-model="form.couponAmount" type="text" placeholder="请输入优惠券抵扣金额" clearable></el-input>
                    </el-form-item>
                    <el-form-item label="门槛金额:" prop="sillAmount" v-if="form.type != 3">
                        <el-input style="width:400px" v-model="form.sillAmount" type="text" placeholder="请输入优惠券门槛金额" clearable></el-input>
                    </el-form-item>
                    <el-form-item label="优惠券信息:" prop="detail">
                        <el-input style="width:400px" v-model="form.detail" type="text" placeholder="请输入优惠券信息" clearable></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="快速设置时间:" prop="isquicly" >
                        <el-switch v-model="isquicly" @change="chengeQuicly"></el-switch>
                    </el-form-item> -->
                    <el-form-item label="有效开始时间:" prop="startTime">
                        <template>
                            <div class="block">
                                <el-date-picker style="width:400px" v-model="form.startTime" type="datetime" default-time="12:00:00" placeholder="选择日期时间">
                                </el-date-picker>
                            </div>
                            <small style="color:#999">可手动输入，例如：日期20180809 时间120000（2018-08-09 12:00:00）</small>
                        </template>
                    </el-form-item>
                    <el-form-item label="有效结束时间:" prop="end_time" >
                        <template>
                            <div class="block">
                                <el-date-picker v-model="form.end_time" type="datetime" style="width:400px" placeholder="选择日期时间">
                                </el-date-picker>
                            </div>
                            <small style="color:#999">可手动输入，例如：日期20180809 时间120000（2018-08-09 12:00:00）</small>
                        </template>
                    </el-form-item>
                    <!-- <el-form-item label="有效结束时间:" prop="end_time" v-else>
                        {{this.$formate(this.form.end_time, "yyyy-MM-dd hh:mm:ss")}}
              
                    </el-form-item> -->
                    <el-form-item label="优惠券状态:" prop="status">
                        <el-radio v-model="form.member_flag" label="0">普通优惠券</el-radio>
                        <el-radio v-model="form.member_flag" label="1">会员优惠券</el-radio>
                        <el-radio v-model="form.member_flag" label="2">代购优惠券</el-radio>
                    </el-form-item>
                    <el-form-item label="优惠券状态:" prop="status">
                        <el-switch  v-model="status"></el-switch>
                        <!-- <el-checkbox v-model="status">{{status ? '有效': '无效'}}</el-checkbox> -->
                    </el-form-item>
                    <el-form-item label="是否关联全部活动:" prop="isAllActivity">
                        <el-switch v-model="isAllActivity"></el-switch>
                    </el-form-item>
                    <el-form-item label="新人专属优惠:" prop="isNewUser">
                        <el-switch v-model="isNewUser"></el-switch>
                    </el-form-item>
                      <el-form-item label="是否关联礼包:" prop="isGiftPack">
                        <el-switch v-model="isGiftPack" @change="handleChangeGift"></el-switch>
                    </el-form-item>
                    <el-form-item v-if="form.member_flag == 0 && isShow3" label="是否指定个人:" prop="isPersonal">
                        <el-switch v-model="isPersonal"></el-switch>
                        <section v-if="isPersonal == true">
                             <div class="selGoods input" style="margin-top:10px;">
                                <section >
                                    <ul>
                                        <li :key="item.id" v-for="item in addUser" style="display:inline-block; margin:5px;line-height:30px;">
                                            <span>{{item.nickName }}</span>
                                            <i title="删除" @click="deleteUser(item.wxUid,$event)" class="el-icon-close"></i>
                                        </li>
                                    </ul>
                                </section>
                            </div>
                            <el-button type="primary" style="margin-left:20px" @click="handleClickUser">选择用户</el-button>
                        </section>
                    </el-form-item>
                    <el-form-item label="设置有效天数:" prop="isvalidity">
                        <el-switch v-model="isvalidity"></el-switch>
                    </el-form-item>
                    <!-- 关联礼包 -->
                    <el-form-item label="关联礼包:" prop="gift" v-if="isGiftPack" >
                        <el-select style="width:400px" v-model="form.gift_pack_coupon_relation" placeholder="选择关联礼包">
                            <el-option v-for="item in giftList" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="有效天数:" prop="validity" v-if="isGiftPack || isvalidity">
                        <el-input style="width:400px" v-model="form.validity" type="text" placeholder="请输入有效天数" clearable></el-input>
                    </el-form-item>
                    <!-- 关联活动 -->
                    <el-form-item label="关联活动:" prop="activityIds"  v-if="!isAllActivity">
                        <div class="selGoods input" style="margin-top:10px;">
                            <section>
                                <ul>
                                    <li :key="item.activityId" v-for="item in addActivityVal" style="display:inline-block;margin:5px;line-height:30px;">
                                        <span>{{item.name}}</span>
                                        <i title="删除" @click="deleteActivity(item.activityId,$event)" class="el-icon-close"></i>
                                    </li>
                                </ul>
                            </section>
                        </div>
                        <el-button type="primary" style="margin-left:20px" @click="handleClick">选择活动</el-button>
                    </el-form-item>
                    <!-- 活动列表 -->
                    <transition name="fade">
                        <div class="popup-detail" v-loading="tableLoading" v-if="isShow">
                            <div class="selGoods">
                                <h3>选择活动</h3>
                                <section>
                                    <ul>
                                        <li :key="item.activityId" v-for="item in addActivityVal" style="display:inline-block;margin:5px;line-height:30px;">
                                            <span>{{item.name}}{{item.activityId}}</span>
                                            <i title="删除" @click="deleteActivity(item.activityId,$event)" class="el-icon-close"></i>
                                        </li>
                                    </ul>
                                </section>
                            </div>
                            <div class="searchList">
                                <el-table class="table-common" ref="multipleTable" :data="searchActicityList" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
                                    <el-table-column type="selection" width="55">
                                    </el-table-column>
                                    <el-table-column prop="name" label="活动名称" width="180">
                                    </el-table-column>
                                    <el-table-column prop="name" label="活动图片" width="180">
                                        <template slot-scope="scope">
                                            <img :src="scope.row.imgUrl" alt="">
                                        </template>
                                    </el-table-column>
                                </el-table>

                                <section class="pagination" v-if="total > 5">
                                    <template v-if="page == 1">
                                        <el-button type="primary" disabled>上一页</el-button>
                                    </template>
                                    <template v-else>
                                        <el-button type="primary" @click="pagePrev">上一页</el-button>
                                    </template>
                                    <template v-if="Math.ceil(total/5) <= page">
                                        <el-button type="primary" disabled>下一页</el-button>
                                    </template>
                                    <template v-else>
                                        <el-button type="primary" @click="pageNext">下一页</el-button>
                                    </template>
                                </section>

                            </div>
                            <section class="bottomAdd" style="margin-top:20px;">
                                <el-button type="primary" @click="addActivity">增加</el-button>
                                <el-button :type="nowSelList && nowSelList.length > 0 ? 'primary' : 'info'" @click="selDone">选择完毕</el-button>
                            </section>
                            <i class="el-icon-circle-close-outline close" title="关闭" @click="close"></i>
                        </div>
                    </transition>
                    <!-- 用户列表 -->
                    <transition name="fade">
                        <div class="popup-detail" v-loading="tableLoading" v-if="isShow2">
                            <div class="selGoods">
                                <h3>选择用户</h3>
                                <section>
                                    <ul>
                                        <li :key="item.id" v-for="item in addUser" style="display:inline-block;margin:5px;line-height:30px;">
                                            <span>{{item.nickName}}</span>
                                            <i title="删除" @click="deleteUser(item.wxUid,$event)" class="el-icon-close"></i>
                                        </li>
                                    </ul>
                                </section>
                            </div>
                            <div class="searchList">
                                <el-input style="width:50%;" class='input' @keyup.enter.native="search" prefix-icon="el-icon-search" clearable v-model="name"  placeholder="请输入查询名称"></el-input>
                                <el-button  type="primary" @click.enter="search" icon="el-icon-search">搜索用户</el-button>
                                <el-table class="table-common" ref="multipleTable" :data="searchUser" tooltip-effect="dark" style="width: 100%; margin-top:20px;" @selection-change="handleSelectionUserChange">
                                    <el-table-column type="selection" width="55">
                                    </el-table-column>
                                    <el-table-column prop="headImage" label="用户头像" width="180">
                                        <template slot-scope="scope">
                                            <img :src="scope.row.headImage" alt="">
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="nickName" label="用户昵称" width="180">
                                    </el-table-column>
                                </el-table>

                                <section class="pagination" v-if="total > 10">
                                    <template v-if="page == 1">
                                        <el-button type="primary" disabled>上一页</el-button>
                                    </template>
                                    <template v-else>
                                        <el-button type="primary" @click="pagePrev">上一页</el-button>
                                    </template>
                                    <template v-if="Math.ceil(total/10) <= page">
                                        <el-button type="primary" disabled>下一页</el-button>
                                    </template>
                                    <template v-else>
                                        <el-button type="primary" @click="pageNext">下一页</el-button>
                                    </template>
                                </section>

                            </div>
                            <section class="bottomAdd" style="margin-top:20px;">
                                <el-button type="primary" @click="addUserList">增加</el-button>
                                <el-button :type="nowUserList && nowUserList.length > 0 ? 'primary' : 'info'" @click="selUserDone">选择完毕</el-button>
                            </section>
                            <i class="el-icon-circle-close-outline close" title="关闭" @click="closeUser"></i>
                        </div>
                    </transition>
                    <el-form-item class='right-btn'>
                        <el-button type="primary" @click="handleSubmit">确定</el-button>
                        <el-button type="primary" style="margin-left:10px" @click="$router.go(-1)">返回</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
import {
    getCouponById,
    allActivityList,
    modifyCoupon,
    getGiftPackList,
    getUsersForBindCoupon
} from "../../data/postData";
export default {
    mounted() {
        var params = {
            data: {
                id: +this.$route.params.id
            }
        };
        this.$fetch.post(getCouponById, params).then(res => {
            this.form = res.data.coupon;
            this.form.member_flag = "" + res.data.coupon.member_flag;
            this.addActivityVal = res.data.coupon.activityInfos;
            this.isAllActivity = res.data.coupon.is_all_activity == 1 ? true : false
            this.isNewUser = res.data.coupon.is_new_user == 1 ? true : false
            this.isGiftPack = res.data.coupon.is_gift_pack == 1 ? true : false
            if(res.data.coupon.is_personal){
                this.isPersonal = res.data.coupon.is_personal == 1 ? true : false
                this.isShow3 = true
            }
            if(res.data.users){
                this.addUser = res.data.users
            }
            this.form.giftPackCouponRelation = res.data.coupon.gift_pack_coupon_relation
            if (res.data.coupon.status == 0) {
                this.status = false;
            }
            if(res.data.coupon.validity && res.data.coupon.validity != 'null'){
                this.isvalidity = true
            }else{
                this.isvalidity = false
            }
        }).catch(err => {});
        this.getGiftPackList()
    },
    data() {
        return {
            mt30: {
                "margin-top": "30px"
            },
            labelPosition: "left",
            user: JSON.parse(localStorage.getItem("ddaigoUser")),
            form: {
                name: "",
                type: "",
                couponAmount: "",
                sillAmount: "",
                startTime: "",
                end_time: "",
                status: "",
                detail: "",
                activityIds: "",
                member_flag: "",
                gift_pack_coupon_relation:'',
                validity: ''
            },
            isShow3: false,
            tableLoading:false,
            giftList:[],
            isNewUser:false,//新人优惠券
            isAllActivity:false,//是否关联全场活动
            isGiftPack:false,//是否关联礼包
            isvalidity:false,//是否设置有效天数
            isquicly:false,//快速设置时间
            total: "",
            page: "",
            size: "",
            isShow: false,
            isShow2: false,//用户
            name:'',
            isPersonal:false,//是否指定个人
            nowUserList: [],
            addUser:[],//指定用户
            searchUser:null,
            nowSelList: [],
            addActivityVal: [],
            searchActicityList: null,
            status: true,
            option: [
                {
                    value: 1,
                    label: "满减券"
                },
                {
                    value: 3,
                    label: "代金券"
                }
                // ,{
                //     value:2,
                //     label:'折扣券'
                // }
            ],
            rules: {
                name: [
                    {
                        required: true,
                        message: "请输入优惠券名称",
                        trigger: "blur"
                    }
                ],
                type: [
                    {
                        required: true,
                        message: "请选择优惠券种类",
                        trigger: "blur"
                    }
                ],
                startTime: [
                    {
                        required: true,
                        message: "请选择活动开始时间",
                        trigger: "blur"
                    }
                ],
                end_time: [
                    {
                        required: true,
                        message: "请活动结束时间",
                        trigger: "blur"
                    }
                ],
                status: [
                    { required: true, message: "请活动状态", trigger: "blur" }
                ],
                couponAmount: [
                    {
                        required: true,
                        message: "请输入优惠券抵扣金额",
                        trigger: "blur"
                    }
                ],
                sillAmount: [
                    {
                        required: true,
                        message: "请输入优惠券门槛金额",
                        trigger: "blur"
                    }
                ],
                detail: [
                    {
                        required: true,
                        message: "请输入优惠券信息",
                        trigger: "blur"
                    }
                ],
                validity: [
                    {
                        required: true,
                        message: "请输入有效天数",
                        trigger: "blur"
                    }
                ],
                activityIds: [
                    {
                        required: true,
                        message: "选择活动",
                        trigger: "blur"
                    }
                ]
            }
        };
    },

    methods: {
        handleChangeGift(){
            this.form.validity = ''
            this.form.gift_pack_coupon_relation = ''
        },
        chengeQuicly(){
           if(this.isquicly){
                this.form.startTime = this.$formate(new Date().getTime(), "yyyy-MM-dd 00:00:00")
                this.form.endTime = '2028-12-29 23:59:59'
           } else{
                this.form.endTime = ''
                this.form.startTime = ''
           }
        },
        //获取礼包
        getGiftPackList(){
            var params = {
                "data":{

                }
            }
            this.$fetch.post(getGiftPackList,params).then(res=>{
                var giftPack = [];
                res.data.forEach(item=>{
                    giftPack.push({
                        id: item.goodsId,
                        name: item.goodsName
                    })
                })
                this.giftList = giftPack
            }).catch(err=>{

            })
        },
        handleClick() {
            this.isShow = true;
            this.tableLoading = true;
            //获取活动列表
            var params = {
                data: {
                    storeNo: this.user.storeNo
                }
            };
            this.$fetch.post(allActivityList, params).then(res => {
                var searchArr = [];
                res.data.forEach(item => {
                    if (item.status == 0 || item.status == 1) {
                        searchArr.push(item);
                    }
                });
                this.searchActicityList = searchArr;
                this.total = res.total;
                this.tableLoading = false;
            }).catch(err => {
                this.$message({
                    message: err.message,
                    type: 'error',
                    duration: 1000
                })
            });
        },
        close() {
            this.isShow = false;
        },
         //用户
        closeUser() {
            this.isShow2= false;
        },
        handleSelectionChange(val) {
            var nowArray = [];
            val.forEach(item => {
                nowArray.push({ activityId: item.id, name: item.name });
            });
            this.nowSelList = nowArray;
        },
        addActivity() {
            let need = [];
            let that = this;
            let arr1 = [];
            let now = [];
            if (this.nowSelList.length > 0) {
                if (this.addActivityVal.length > 0) {
                    now = this.addActivityVal.concat(this.nowSelList);
                    var unique = {};
                    now.forEach(function(gpa) {
                        unique[JSON.stringify(gpa)] = gpa;
                    });
                    now = Object.keys(unique).map(function(u) {
                        return JSON.parse(u);
                    });
                    this.addActivityVal = now;
                } else {
                    this.addActivityVal = this.addActivityVal.concat(
                        this.nowSelList
                    );
                }
            }
            this.$refs.multipleTable.clearSelection();
            this.nowSelList = "";
        },
         //用户
        addUserList() {
            let needUser = [];
            let that = this;
            let arrUser = [];
            let nowUser = [];
            if (this.nowUserList.length > 0) {
                if (this.addUser.length > 0) {
                    nowUser = this.addUser.concat(this.nowUserList);
                    var uniqueUser = {};
                    nowUser.forEach(function(gpa) {
                        uniqueUser[JSON.stringify(gpa)] = gpa;
                    });
                    nowUser = Object.keys(uniqueUser).map(function(u) {
                        return JSON.parse(u);
                    });
                    this.addUser = nowUser;
                } else {
                    this.addUser = this.addUser.concat(
                        this.nowUserList
                    );
                }
            }
            this.$refs.multipleTable.clearSelection();
            this.nowUserList = "";
        },
        selDone() {
            this.addActivity();
            this.close();
        },
         //用户
        handleSelectionUserChange(val) {
            this.nowUserList = val;
        },
        deleteActivity(id, e) {
            this.addActivityVal.forEach((val, i) => {
                if (val.activityId == id) {
                    this.addActivityVal.splice(i, 1);
                }
            });
        },
        deleteUser(id, e) {
            this.addUser.forEach((val, i) => {
                if (val.wxUid == id) {
                    this.addUser.splice(i, 1);
                }
            });
        },
         //用户
        selUserDone() {
            this.addUserList();
            this.closeUser();
        },
        //用户列表
        handleClickUser(){
            this.isShow2 = true
        },
        //查询用户
        search(){
            var params = {
                "data": {
                    "name": this.name
                }
            }
            this.$fetch.post(getUsersForBindCoupon, params).then(res => {
                console.log(res.data)
                this.searchUser = res.data
                this.total = res.total
            }).catch( err => {
                this.$message({
                    message: err.message,
                    type: 'error',
                    duration: 1000
                })
            })
        },
        handleSubmit() {
            if (this.addActivityVal.length > 0) {
                var arr12 = [];
                this.addActivityVal.forEach(item => {
                    arr12.push(item.activityId);
                });
                this.form.activityIds = arr12.toString();
            } else {
                this.$message({
                    message: "请选择优惠券关联活动",
                    type: "warning",
                    duration: 1500
                });
            }
            let {name,type,couponAmount,sillAmount,startTime,end_time,endTime,detail,activityIds,member_flag} = this.form
           
            if (name == "") {
                this.$message({
                    message: "请填写优惠券名称",
                    type: "warning",
                    duration: 1500
                });
            } else if (type == "") {
                this.$message({
                    message: "请填写优惠券类别",
                    type: "warning",
                    duration: 1500
                });
            } else if (couponAmount == "") {
                this.$message({
                    message: "请输入优惠券抵扣金额",
                    type: "warning",
                    duration: 1500
                });
            } else if (sillAmount == "" && this.form.type != 3) {
                this.$message({
                    message: "请输入优惠券门槛金额",
                    type: "warning",
                    duration: 1500
                });
            }else if(this.form.type !=3 && (+couponAmount) > (+sillAmount) ){
                this.$message({
                    message: "优惠券门槛金额应大于抵扣金额",
                    type: "warning",
                    duration: 1500
                });
            } else if (startTime == "") {
                this.$message({
                    message: "请选择优惠券有效开始时间",
                    type: "warning",
                    duration: 1500
                });
            } else if (end_time == "") {
                this.$message({
                    message: "请选择优惠券有效结束时间",
                    type: "warning",
                    duration: 1500
                });
            } else if (
                new Date(end_time) > new Date(endTime)
            ) {
                this.$message({
                    message: "请正确选择开始结束时间",
                    type: "warning",
                    duration: 1500
                });
            }
            else if (!this.isAllActivity && activityIds.length < 1) {
                this.$message({
                    message: "请选择优惠券关联活动",
                    type: "warning",
                    duration: 1500
                });
            } else if (detail == "") {
                this.$message({
                    message: "请选择优惠券信息",
                    type: "warning",
                    duration: 1500
                });
            } 
            else if ((this.isGiftPack || this.isvalidity) && (this.form.validity === '' || !/^[1-9]\d*$/.test((+this.form.validity)))) {
                this.$message({
                    message: "有效天数不能为空,并且为整数",
                    type: "warning",
                    duration: 1500
                });
            }else if (this.isGiftPack && this.form.gift_pack_coupon_relation === '') {
                this.$message({
                    message: "关联的礼包不能为空",
                    type: "warning",
                    duration: 1500
                });
            } else if (this.isPersonal && this.addUser.length < 0){
                this.$message({
                    message: "选择指定用户",
                    type: "warning",
                    duration: 1500
                });
            }else {
                if(this.form.type == 3){
                    if(!this.isGiftPack){
                        var params = {
                            data: {
                                id: this.$route.params.id,
                                name: name,
                                type: "" + type,
                                status: this.status ? '1' : '0',
                                couponAmount: "" + couponAmount,
                                startTime: this.$formate(
                                    new Date(startTime).getTime(),
                                    "yyyy-MM-dd hh:mm:ss"
                                ),
                                endTime: this.$formate(
                                    new Date(end_time).getTime(),
                                    "yyyy-MM-dd hh:mm:ss"
                                ),
                                activityIds: "" + activityIds,
                                detail: detail,
                                memberFlag: member_flag,
                                isAllActivity: this.isAllActivity ? '1' : '0',
                                isNewUser : this.isNewUser ? '1' : '0',
                                isGiftPack : this.isGiftPack ? '1' : '0',
                                // validity: '' + this.form.validity,
                                //giftPackCouponRelation: '' + this.form.gift_pack_coupon_relation
                            }
                        };
                    }else{

                        var params = {
                            data: {
                                id: this.$route.params.id,
                                name: name,
                                type: "" + type,
                                status: this.status ? '1' : '0',
                                couponAmount: "" + couponAmount,
                                startTime: this.$formate(
                                    new Date(startTime).getTime(),
                                    "yyyy-MM-dd hh:mm:ss"
                                ),
                                endTime: this.$formate(
                                    new Date(end_time).getTime(),
                                    "yyyy-MM-dd hh:mm:ss"
                                ),
                                activityIds: "" + activityIds,
                                detail: detail,
                                memberFlag: member_flag,
                                isAllActivity: this.isAllActivity ? '1' : '0',
                                isNewUser : this.isNewUser ? '1' : '0',
                                isGiftPack : this.isGiftPack ? '1' : '0',
                                validity: '' + this.form.validity,
                                giftPackCouponRelation: '' + this.form.gift_pack_coupon_relation
                            }
                        };
                    }
                }else{
                    if(this.isvalidity){

                        var params = {
                            data: {
                                id: this.$route.params.id,
                                name: name,
                                type: "" + type,
                                status: this.status ? '1' : '0',
                                couponAmount: "" + couponAmount,
                                sillAmount: "" + sillAmount,
                                startTime: this.$formate(new Date(startTime).getTime(), "yyyy-MM-dd hh:mm:ss"),
                                endTime: this.$formate( new Date(end_time).getTime(), "yyyy-MM-dd hh:mm:ss"),
                                activityIds: "" + activityIds,
                                detail: detail,
                                memberFlag: member_flag,
                                isAllActivity: this.isAllActivity ? '1' : '0',
                                isNewUser : this.isNewUser ? '1' : '0',
                                isGiftPack : this.isGiftPack ? '1' : '0',
                                validity: this.form.validity ,
                               // giftPackCouponRelation: ''
                            }
                        };
                    }else{
                        var params = {
                            data: {
                                id: this.$route.params.id,
                                name: name,
                                type: "" + type,
                                status: this.status ? '1' : '0',
                                couponAmount: "" + couponAmount,
                                sillAmount: "" + sillAmount,
                                startTime: this.$formate(new Date(startTime).getTime(), "yyyy-MM-dd hh:mm:ss"),
                                endTime: this.$formate( new Date(end_time).getTime(), "yyyy-MM-dd hh:mm:ss"),
                                activityIds: "" + activityIds,
                                detail: detail,
                                memberFlag: member_flag,
                                isAllActivity: this.isAllActivity ? '1' : '0',
                                isNewUser : this.isNewUser ? '1' : '0',
                                isGiftPack : this.isGiftPack ? '1' : '0',
                                //validity: this.form.validity ,
                               // giftPackCouponRelation: ''
                            }
                        };
                    }
                }
                if(this.isPersonal){
                    var userArr1 = []
                    this.addUser.forEach(item => {
                        userArr1.push(item.wxUid)
                    })
                    this.wxUids = userArr1
                    params.data.isPersonal = '1'
                    params.data.wxUids = this.wxUids
                    
                }
                this.$fetch.post(modifyCoupon, params).then(res => {
                    this.$message({
                        message: res.message,
                        type: "success",
                        duration: 1000
                    });
                    setTimeout(() => {
                        this.$router.go(-1);
                    }, 1500);
                }).catch(err => {
                    this.$message({
                        message: err.message,
                        type: "error",
                        duration: 1000
                    });
                });
            }
        }
    }
};
</script>

<style scoped lang="less">
@import url("../../style/activity.less");
h3 {
    margin: 20px 0;
}
.input {
    width: 400px;
}
.selGoods {
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
    section {
        padding: 20px 0;
        border: 1px solid #ccc;
        border-radius: 10px;
    }
}
.right-btn {
    float: right;
    margin-right: 10%;
}
</style>
[{id:'270',name:'粉红发布娃娃'}]